'use strict';

const Controller = require('egg').Controller;
const util = require("util");

const Koa = require('koa');
const app = new Koa();
const bodyParser = require('koa-bodyparser');

// 使用ctx.body解析中间件
app.use(bodyParser());

class equipmentController extends Controller {

  //首页
  async index() {
    const { ctx } = this;
    ctx.body = {
      data: '/findEquipmentAll 查看所有设备列表  /updateEquipmentById   根据id更新设备信息 /findEquipmentById 根据id查询设备  /insertEquipment 插入新设备  /deleteEquipmentById  根据id删除设备'
    };
  }
  //查询所有仪器信息的方法
  async findEquipmentAll() {
    const { ctx } = this;
    const result = await ctx.service.equipment.findEquipmentAll();
    ctx.body = result;
  }
  //根据设备编号修改仪器信息
  async updateEquipmentByNumber() {
    const { ctx } = this;
    const equipment_number = ctx.request.body.equipment_number;
    const equipment_name = ctx.request.body.equipment_name;
    const equipment_price = ctx.request.body.equipment_price;
    const result = await this.service.equipment.updateEquipmentByNumber(equipment_number,equipment_name,equipment_price);
    ctx.body = result;
  }
  //根据设备编号查询设备
  async findEquipmentByNumber() {
    const { ctx } = this;
    const postData = ctx.request.body;
    const result = await this.service.equipment.findEquipmentByNumber(postData);
    ctx.body = result;
  }

  //新增仪器
  async insertEquipment() {
    const { ctx } = this;
    const postData = ctx.request.body;
    const result = await ctx.service.equipment.insertEquipment(postData);
    ctx.body = result;
  }
  //根据设备编号删除仪器
  async deleteEquipmentByNumber() {
    const { ctx } = this;
    const postData = ctx.request.body;
    const result = await ctx.service.equipment.deleteEquipmentByNumber(postData);
    ctx.body = result;
  }
}
module.exports = equipmentController;